package digest;

import org.apache.commons.digester.Digester;
import org.apache.commons.digester.xmlrules.DigesterLoader;
import org.xml.sax.SAXException;

import java.io.IOException;

public class TestDigestParser {


    public static void main(String[] args) {

        //加载配置文件，获得解析器
        Digester digester= DigesterLoader.createDigester(TestDigestParser.class
                                                                         .getClassLoader()
                                                                         .getResource("digest/rule.xml"));




        //准备一个空的根元素所对应的对象，交给解析器，解析器会将解析的数据set到这个对象中
        ClassBean classBean=new ClassBean();
        digester.push(classBean);


        //解析xml文件
        try {
            digester.parse(TestDigestParser.class
                                           .getClassLoader()
                                           .getResourceAsStream("students.xml"));


        } catch (IOException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        }






        String name=classBean.findStudent(2).getName();

        System.out.println(name);

        String sex=classBean.findStudent(1).getSex();

        System.out.println(sex);
























    }


}
